<template>
  <div style="padding-left: 20px; padding-right: 20px">
    <div>
      <el-radio-group v-model="typeInfo.clientType">
        <el-radio :label="1">系统</el-radio>
        <el-radio :label="2">企业</el-radio>
      </el-radio-group>
    </div>
    <div style="padding-top: 10px; text-align: right">
      <el-button type="primary" @click="handleSubmit">保存</el-button>
    </div>
  </div>
</template>
<script>
import { getClientType, addClientType, updateClientType } from "@/api/identity";
export default {
  data() {
    return {
      typeInfo: {
        id: null,
        clientId: null,
        clientType: null,
      },
    };
  },
  methods: {
    getData() {
      if (!this.clientId) return;
      getClientType(this.clientId).then((res) => {
        if (res) {
          this.typeInfo = {
            id: res.id,
            clientId: res.clientId,
            clientType: res.clientType,
          };
        }
      });
    },
    handleSubmit() {
      if (!this.typeInfo.id) {
        this.typeInfo.clientId = this.clientId;
        addClientType(this.typeInfo).then((res) => {
          if (res) {
            this.$notify({
              title: "成功",
              message: "保存成功",
              type: "success",
              position: "bottom-right",
            });
          }
        });
      } else {
        updateClientType(this.typeInfo).then((res) => {
          if (res) {
            this.$notify({
              title: "成功",
              message: "保存成功",
              type: "success",
              position: "bottom-right",
            });
          }
        });
      }
    },
  },
  mounted() {},
  watch: {
    clientId: {
      handler(value) {
        this.getData();
      },
      immediate: true,
    },
  },
  props: {
    clientId: {
      type: String,
      default: null,
    },
  },
};
</script>
<style scoped></style>
